<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>知识</title>
    <%@include file="/common/commonCSS.jsp" %>
    <%@include file="/common/commonJS.jsp" %>
    <%@include file="/WEB-INF/jsp/include/taglib.jsp" %>
</head>

<body>
    <div class="main-container" id="main-container">

        <div class="row" style="margin-top: 20px;">
            <div class="col-md-12">
                <form class="layui-form" id="search-from" action="${webRoot}/questionnaire/answerList">
                    <div class="layui-form-item">
                        <%--<label class="layui-form-label" style="width:6%;">标题:</label>--%>
                        <div class="layui-input-inline">
                            <input type="text" name="name" value="${questionnaire.name}"  placeholder="请输入名称"  class="layui-input" >
                        </div>
                        <button class="layui-btn" id="searchSubmit"><i class="layui-icon">&#xe615;</i>搜 索</button>
                        <button class="layui-btn layui-btn-normal" type="button" id="refresh"><i class="layui-icon">&#x1005;</i>重 置</button>
                        <%--<button class="layui-btn " type="button" onclick="getView()" id=""><i class="layui-icon">&#xe61f;</i>新 增</button>--%>
                    </div>
                </form>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <table id="table-list" class="layui-table" lay-size="sm">
                    <thead>
                        <tr>
                            <th>序号</th>
                            <th>名称</th>
                            <%--<th>描述</th>--%>
                            <%--<th>开始时间</th>--%>
                            <%--<th>结束时间</th>--%>
                            <th>状态</th>
                            <th>操作</th>

                        </tr>
                    </thead>
                    <tbody>
                        <c:forEach items="${page.result}" var="questionnaire" varStatus="i">
                            <tr id="questionnaire${questionnaire.id }">
                                <td>${i.index+1 }</td>
                                <td>${questionnaire.name}</td>
                                <%--<td>${questionnaire.content}</td>--%>
                                <%--<td><fmt:formatDate value="${questionnaire.startTime}" pattern="yyyy-MM-dd hh:mm:ss"/></td>--%>
                                <%--<td><fmt:formatDate value="${questionnaire.endTime}" pattern="yyyy-MM-dd hh:mm:ss"/></td>--%>
                                <td>${fns:getCodeName("questionnaire_status",questionnaire.status)}</td>
                                <td>
                                    <div class=" btn-group ">
                                        <c:if test="${questionnaire.status == 2}">
                                            <a class="layui-btn layui-btn-small" title="作答" href="${webRoot}/questionnaire/answerSurvey?id=${questionnaire.id}" ><i class="layui-icon">&#xe642;</i>填写问卷</a>
                                        </c:if>
                                    </div>
                                </td>
                            </tr>
                        </c:forEach>
                    </tbody>
                </table>
                <sys:page page="${page}"></sys:page>
            </div>
        </div>
    </div>
</body>
<script>
    function getView() {
        var html = '<div class="row" style="margin:0">' +
					'<div class="form-group col-xs-12 " style="margin-top:15px;">' +
						'<label class="col-xs-3 control-label no-padding-right"><i class="red"> * </i>标题:</label>' +
						'<div class="col-xs-9">' +
							'<span class="col-xs-11 block input-icon input-icon-right">' +
								'<input id="title" name="title" type="text"  class="form-control"/>' +
							'</span>' +
						'</div>' +
					'</div>' +
				'</div>'
        layer.open({
            scrollbar: false,
            type: 1,
            title : ["新建调查问卷" , true],
            area: ['400px', '200px'], //宽高
            content: html,
            shadeClose : false,
            btn: ['确认', '取消'],
            yes: function(index, layero){
                var title = $('#title').val();
                if(!title){
                    alert('请输入标题!');
                    return;
                }
                console.log(title);
                var url ="${webRoot}/questionnaire/addSurvey";
                $.post(url,"title="+title,function (r) {
                    if(r.code=='0'){
                        location.href='${webRoot}/questionnaire/designSurvey?id='+r.questionnaireInfo.id;
                    }else {
                        alertMsg(r.msg);
                    }
                });
            },
            btn2: function(index, layero){

            }
        });
    }
    function publishSurveyById(id) {
        var url = "${webRoot}/questionnaire/publishSurvey";
        confirm('确定要发布选中的问卷？', function(){
            $.post(url,"id="+id,function (r) {
                if(r.code=='0'){
                    toast(r.msg);
                    location.href='${webRoot}/questionnaire/list';
                }else {
                    alertMsg(r.msg);
                }
            });
        });
    }
    function deleteById(id) {
        var url ="${webRoot}/questionnaire/delete";
        confirm('确定要删除选中的问卷？', function(){
            $.post(url,"id="+id,function (r) {
                if(r.code=='0'){
                    toast(r.msg);
                    $("#questionnaire_"+id+"").remove();
                    location.href='${webRoot}/questionnaire/list';
                }else {
                    alertMsg(r.msg);
                }
            });
        });
    }
</script>

</html>